#!/bin/bash

# 自动设置ROS环境
echo "正在设置ROS环境..."

# 设置ROS环境变量
source /opt/ros/noetic/setup.bash
source /root/catkin_ws/devel/setup.bash

# 确保脚本有执行权限
chmod +x /root/catkin_ws/src/auto_navigation/scripts/*.sh
chmod +x /root/catkin_ws/src/auto_navigation/scripts/*.py

# 更新所有脚本文件，确保它们不再需要手动source环境
find /root/catkin_ws/src/auto_navigation/scripts -name "*.sh" -type f -exec sed -i '0,/source \/opt\/ros\/noetic\/setup.bash/s//# ROS环境已通过setup_env.sh加载\n# source \/opt\/ros\/noetic\/setup.bash/' {} \;
find /root/catkin_ws/src/auto_navigation/scripts -name "*.sh" -type f -exec sed -i '0,/source \/root\/catkin_ws\/devel\/setup.bash/s//# source \/root\/catkin_ws\/devel\/setup.bash/' {} \;

echo "ROS环境已设置完成！"
echo "请使用 'source /root/catkin_ws/src/auto_navigation/scripts/setup_env.sh' 命令加载ROS环境"

# 显示当前可用的脚本
echo -e "\n可用的脚本命令："
echo "-----------------------------------"
echo "构建NDT地图: /root/catkin_ws/src/auto_navigation/scripts/build_ndt_map_from_bag.sh"
echo "运行NDT定位: /root/catkin_ws/src/auto_navigation/scripts/run_ndt_localization_with_bag.sh"
echo "创建ROS bag: /root/catkin_ws/src/auto_navigation/scripts/create_kitti_rosbag.sh"
echo "播放ROS bag: /root/catkin_ws/src/auto_navigation/scripts/play_kitti_bag.sh"
echo "导出点云数据: /root/catkin_ws/src/auto_navigation/scripts/export_map_simple.sh"
echo "上传到Git仓库: /root/catkin_ws/src/auto_navigation/scripts/upload_to_git.sh"
echo "-----------------------------------"

# 将当前环境变量添加到当前shell
exec bash 